<?php defined('SYSPATH') or die(); ?>
<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>思途CMS{$coreVersion}</title>
    {template 'stourtravel/public/public_min_js'}
    {php echo Common::getCss('style.css,base.css,base_new.css,../js/jqueryui/jquery-ui.min.css'); }
    {php echo Common::getScript("uploadify/jquery.uploadify.min.js,choose.js,product_add.js,laydate/laydate.js,imageup.js,jquery.upload.js"); }
    {php echo Common::getCss('uploadify.css','js/uploadify/'); }
    {Common::css_plugin('promo.css','promo')}
</head>

<body>

<!--顶部-->
{php Common::getEditor('jseditor','',$sysconfig['cfg_admin_htmleditor_width'],300,'Sline','','print',true);}
<table class="content-tab">
    <tr>
        <td width="119px" class="content-lt-td" valign="top">
            {template 'stourtravel/public/leftnav'}
            <!--右侧内容区-->
        </td>
        <td valign="top" class="content-rt-td" style="overflow:auto;">
            <form id="product_fm">
                <div class="cfg-header-bar">
                    <a href="javascript:;" class="fr btn btn-primary radius mt-6 mr-10" onclick="window.location.reload()">刷新</a>
                </div>
                <div class="product-add-div" id="content_basic">
                    <ul class="info-item-block">
                        <li>
                            <span class="item-hd">首页挂件：</span>
                            <div class="item-bd">
                                <label class="radio-label w80"><input type="radio" name="cfg_promo_pendant_status" {if !$config['cfg_promo_pendant_status'] || $config['cfg_promo_pendant_status']==0}checked{/if} value="0">关闭</label>
                                <label class="radio-label w80"><input type="radio" name="cfg_promo_pendant_status" {if $config['cfg_promo_pendant_status']==1}checked{/if} value="1">开启</label>
                            </div>
                        </li>
                        <li>
                            <span class="item-hd">挂件图片：</span>
                            <div class="item-bd">
                                <span class="item-text">建议尺寸200*200</span>
                                <div class="custom-bg-block mt-5 coupon-img">
                                    <a href="javascript:;" class="custom-bg-btn" onclick="upload_img($(this),2)">
                                        <div class="add-upload" {if $config['cfg_promo_pendant_img']}style="display: none"{/if}>
                                            <i class="upload-icon"></i>
                                            <div class="upload-txt">上传图片</div>
                                        </div>
                                        {if $config['cfg_promo_pendant_img']}
                                        <img src="{$config['cfg_promo_pendant_img']}" class="upload-img">
                                        {else}
                                        <img src="" class="upload-img" style="display: none">
                                        {/if}
                                        <input type="hidden" name="cfg_promo_pendant_img" value="{$config['cfg_promo_pendant_img']}">
                                    </a>
                                </div>
                            </div>
                        </li>
                        <li>
                            <span class="item-hd">跳转页面：</span>
                            <div class="item-bd">
                                <input class="btn radius btn-secondary size-S mt-5" type="button" onclick="add_link()" value="选择">
                                <div>
                                    {if $config['link']['ad_type']==1}
                                    <span class="item-text jump-url">{$config['link']['dis']}</span>
                                    {elseif $config['link']['ad_type']==2}
                                    <span class="item-text jump-url">内链：{$config['link']['path']}</span>
                                    {elseif $config['link']['ad_type']==3}
                                    <span class="item-text jump-url">自定义外链：{$config['link']['path']}</span>
                                    {elseif $config['link']['ad_type']==4}
                                    <span class="item-text jump-url">跳转三方小程序：{$config['link']['path']}</span>
                                    {else}
                                    <span class="item-text jump-url"></span>
                                    {/if}
                                    <input type="hidden" name="cfg_promo_pendant_link" value="{$config['cfg_promo_pendant_link']}">
                                </div>
                            </div>
                        </li>
                    </ul>
                </div>
            </form>
            <div class="clear clearfix pt-20 pb-20">
                <a class="btn btn-primary radius size-L ml-115" id="save_btn" href="javascript:;">保存</a>
            </div>
        </td>
    </tr>
</table>

<script>
    function add_link()
    {
        ST.Util.showBox('编辑uniapp导航链接',SITEURL+'uniapp/dialog_nav_link',900,600,null,null,document,{loadWindow:window,loadCallback: saveLink});
    }

    function saveLink(res, status)
    {
        var ad_type = res.adType;
        var data = '';
        if(res.data[0]){
            res.data[0]["ad_type"] = ad_type;
            data = res.data[0];
        }else{
            res.data['ad_type'] = ad_type;
            data = res.data;
        }
        var json = encodeURIComponent(JSON.stringify(data));

        if(data.ad_type==1){
            $('.jump-url').html(data.dis);
        }else{
            if(data.ad_type==2){
                $('.jump-url').html('内链：'+data.path);
            }else if(data.ad_type==3) {
                $('.jump-url').html('自定义地址：'+data.path);
            }else{
                $('.jump-url').html('跳转三方小程序：'+data.path);
            }
        }
        $("[name='cfg_promo_pendant_link']").val(json);
    }

    function upload_img(obj,type)
    {
        ST.Util.showBox('上传图片', SITEURL + 'image/insert_view', 0,0, null, null, document, {loadWindow: window, loadCallback: Insert});
        function Insert(result,bool){
            var temp =result.data[0].split('$$');
            $('.add-upload').hide();
            $('.upload-img').attr('src',temp[0]).show();
            $('input[name="cfg_promo_pendant_img"]').val(temp[0]);
        }
    }

    $(document).ready(function (e) {
        $("#save_btn").click(function (e) {
            var pendant_status = $("input[name='cfg_promo_pendant_status']:checked").val();
            if(pendant_status === '1'){
                var img = $('input[name="cfg_promo_pendant_img"]').val();
                var link = $('input[name="cfg_promo_pendant_link"]').val();
                if(!img){
                    ST.Util.showMsg('请上传挂件图片', 5);
                    return false;
                }
                if(!link){
                    ST.Util.showMsg('请选择跳转页面', 5);
                    return false;
                }
            }
            $.ajaxform({
                url: SITEURL + "promo/admin/promo/ajax_pendant_save",
                method: "POST",
                form: "#product_fm",
                dataType: "JSON",
                success: function (result) {
                    if (!result.status) {
                        ST.Util.showMsg(result.msg, 5);
                    } else {
                        ST.Util.showMsg('保存成功', 4)
                    }
                }
            });
        });
    });
</script>
</body>
</html>
